package com.text.viewpageviewpage;


import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    public List<View> mViews;
    private ViewPager mViewPage;
    public View mView1;
    public View mView2;
    public View mView3;
    private MyPageAdapter mMyPageAdapter;


    ViewPager mViewPager;

    TextView mTvImageDesc;
    private List<ImageView> mImageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//版本判断
            // Translucent status bar
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//设置statusbar应用所占的屏幕扩大到全屏，但是最顶上会有背景透明的状态栏，它的文字可能会盖着你的应用的标题栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViewPage = findViewById(R.id.vp_main_homepage);
        mView1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view1, null);

        mViewPager = mView1.findViewById(R.id.view_pager);
        mTvImageDesc = mView1.findViewById(R.id.tv_image_desc);
        initView();


        mView2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view2, null);
        mView3 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view3, null);
        mViews = new ArrayList<>();
        mViews.add(mView1);
        mViews.add(mView2);
        mViews.add(mView3);
        mMyPageAdapter = new MyPageAdapter(mViews, MainActivity.this);
        mViewPage.setAdapter(mMyPageAdapter);
    }


    private void initView() {
        initData();
        CarouselAdapter mAdapter = new CarouselAdapter(mImageList, mViewPager);
        mViewPager.setAdapter(mAdapter);//第二步：设置viewpager适配器

    }


    /**
     * 第一步：初始化数据
     */
    //初始化图片轮播的图片
    private void initData() {
        int[] imageResIDs = {
                R.drawable.tablayout1text1,
                R.drawable.tablayout1text2,
                R.drawable.tablayout1text3,
                R.drawable.tablayout1text4,
        };
        mImageList = new ArrayList<>();
        ImageView iv;
        for (int i = 0; i < imageResIDs.length; i++) {
            iv = new ImageView(this);
            iv.setBackgroundResource(imageResIDs[i]);
            mImageList.add(iv);

        }
    }


}